﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonDAL;
using CommonLib;
using System.Data.Common;
using DBHelperLib;

namespace Cinema.DAL
{

    internal class FilmDataEntity : DataEntityL<FilmUniqueKey, IFilm>, IFilm, IFilmDataEntity
    {
        // protected FilmDataMapper DataMapper { get; set; }

        IFromFilmObjectMapper Mapper { get; set; }

        public FilmDataEntity(
            long identity, IFilm businessEntity, long version, IFromFilmObjectMapper mapper) :
            base(identity, businessEntity, version)
        {
            Mapper = mapper;
        }

        public FilmDataEntity(IFilm businessEntity, IFromFilmObjectMapper mapper) :
            base(businessEntity)
        {
            Mapper = mapper;
        }

        #region IFilm Members

        public string Name
        {
            get
            {
                return BusinessEntity.Name;
            }
            set
            {
                BusinessEntity.Name = value;
                OnDirty();
            }
        }

        public string Description
        {
            get
            {
                return BusinessEntity.Description;
            }
            set
            {
                BusinessEntity.Description = value;
                OnDirty();
            }
        }

        public string Director
        {
            get
            {
                return BusinessEntity.Director;
            }
            set
            {
                BusinessEntity.Director = value;
                OnDirty();
            }
        }

        public PositiveValue<short> Duration
        {
            get
            {
                return BusinessEntity.Duration;
            }
            set
            {
                BusinessEntity.Duration = value;
                OnDirty();
            }
        }

        public string ImagePath
        {
            get
            {
                return BusinessEntity.ImagePath;
            }
            set
            {
                BusinessEntity.ImagePath = value;
                OnDirty();
            }
        }

        public DateTime? DiscontinueDate
        {
            get
            {
                return BusinessEntity.DiscontinueDate;
            }
            set
            {
                BusinessEntity.DiscontinueDate = value;
                OnDirty();
            }
        }

        #endregion


        protected override int UpdateEntity()
        {
            return Mapper.Update(this);
        }

        protected override long InsertEntity()
        {
            return Mapper.Insert(this);
        }

        protected override int DeleteEntity()
        {
            return Mapper.Delete(this);
        }
    }

    internal class FilmLazyEntity : LazyDataEntityL<FilmUniqueKey, IFilm, IFilmDataEntity>, IFilm
    {
        public FilmLazyEntity(long identity, FilmDataMapper dataMapper) :
            base(identity, dataMapper)
        {
        }

        #region IFilm Members

        public string Name
        {
            get
            {
                return DataEntity.Name;
            }
            set
            {
                DataEntity.Name = value;
            }
        }

        public string Description
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Director
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public PositiveValue<short> Duration
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string ImagePath
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public DateTime? DiscontinueDate
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion
    }
}
